package com.tong.embeddedvr.Mapper;

import com.tong.embeddedvr.dto.HostAccountDTO;
import com.tong.embeddedvr.entity.HostAccountEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

@Repository
@Mapper
public interface HostAccountMapper {

    /**
     * @Description 获得所有的hostAccount, 这里的hostAccount不再包含内部的host对象
     * @Author gcl
     * @Date 2021/1/28 16:54
     * @param:
     * @Return java.util.ArrayList<com.tong.embeddedvr.dto.HostAccountDTO>
     */
    @Select("SELECT * FROM host_account WHERE host_account_is_delete = 0")
    public ArrayList<HostAccountDTO> getAllHostAccount();

    /**
     * @Description 添加一个hostAccount
     * @Author gcl
     * @Date 2021/1/28 16:54
     * @param: map
     * @Return void
     */
    @Insert("INSERT INTO host_account(host_account_username,host_account_password,host_id,host_account_start_use_time,user_id,host_account_state) VALUES(#{hostAccountEntity.hostAccountUsername},#{hostAccountEntity.hostAccountPassword},#{hostAccountEntity.hostId},#{hostAccountEntity.hostAccountStartUseTime},#{hostAccountEntity.userId},#{hostAccountEntity.hostAccountState})")
    public void addHostAccount(@Param("hostAccountEntity") HostAccountEntity hostAccountEntity);

    /**
     * @Description 更新hostAccount信息
     * @Author gcl
     * @Date 2021/1/28 18:40
     * @param: hostAccountEntity
     * @Return void
     */
    public void updateInformation(@Param("hostAccountEntity") HostAccountEntity hostAccountEntity);

    /*
     * @Description 根据hostAccountId获得对应的hostAccount信息,不再获得包含内部的host对象
     * @Author gcl
     * @Date 2021/1/28 18:47
     * @param: hostAccountEntity
     * @Return com.tong.embeddedvr.dto.HostAccountDTO
     */
    @Select("SELECT * FROM host_account WHERE host_account_id = #{hostAccountEntity.hostAccountId} AND host_account_is_delete = 0")
    public HostAccountDTO getHostAccountById(@Param("hostAccountEntity") HostAccountEntity hostAccountEntity);

    /**
     * @Description 根据用户id获得hostAccount,因为每位用户只能用一台主机.3中获取方式:session,sql,分配
     * @Author gcl
     * @Date 2021/3/6 19:54
     * @param: hostAccountEntity
     * @Return HostAccountDTO
     */
    @Select("SELECT * FROM host_account WHERE user_id = #{hostAccountEntity.userId} && host_account_state = 1 AND host_account_is_delete = 0")
    public HostAccountDTO getHostAcountByUserId(@Param("hostAccountEntity") HostAccountEntity hostAccountEntity);

    /**
     * @Description 根据hostId获得对应的hostAccount信息, 不再获得包含内部的host对象
     * @Author gcl
     * @Date 2021/1/28 18:48
     * @param: hostAccountEntity
     * @Return com.tong.embeddedvr.dto.HostAccountDTO[]
     */
    @Select("SELECT * FROM host_account WHERE #{hostAccountEntity.hostId} = host_id AND host_account_is_delete = 0")
    public HostAccountDTO[] getHostAccountsByHostId(@Param("hostAccountEntity") HostAccountEntity hostAccountEntity);

}
